<?php
declare(strict_types=1);
namespace cms\fkw\admin\api_controller;

use cms\fkw\request\AppFormRequest;
use cms\fkw\service\AppService;
use Hyperf\Di\Annotation\Inject;
use Hyperf\HttpServer\Annotation\Controller;
use Hyperf\HttpServer\Annotation\PostMapping;
use Hyperf\HttpServer\Annotation\RequestMapping;
use Psr\Http\Message\ResponseInterface;

/**
 * Class AppController
 * @package cms\fkw\admin\api_controller
 * @Controller(prefix="api/fkw/admin_app")
 */
class AppController extends CommonController
{
    /**
     * @Inject()
     * @var AppService
     */
    protected AppService $appService;

    /**
     * @param AppFormRequest $request
     * @return ResponseInterface
     * @PostMapping(path="create")
     */
    public function create(AppFormRequest $request): ResponseInterface
    {
        $form_data = $request->validated();
        $result = $this->appService->model->create($form_data);
        return $this->success('请求成功', $result);
    }

    /**
     * @return ResponseInterface
     * @RequestMapping(path="retrieve")
     */
    public function retrieve(): ResponseInterface
    {
        $where = [];
        $result = $this->appService->model->where($where)->paginate(10);
        return $this->success('请求成功', [
            'total' => $result->total(),
            'items' => $result->items()
        ]);
    }
}